<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本框变色</title>
</head>

<body>
    <div id="box">
        <input type="text" value="1">
        <input type="text" value="2">
        <input type="text" value="3">
        <input type="text" value="4">
        <input type="text" value="5">
        <input type="text" value="6">
        <input type="text" value="7">
        <input type="text" value="8">
        <input type="text" value="9">
        <input type="text" value="10">
    </div>
</body>
<script>
    var box = document.getElementById("box");
    var inputs = box.children;

    box.onclick = function(e){
        var e = e || window.event;
            ele = e.target || e.srcElement;
        
        for (let index = 0; index < inputs.length; index++) {
            const element = inputs[index];
            element.style.backgroundColor = '#fff';
        }
        ele.style.backgroundColor = '#ccc';
    }
</script>

</html>